#ifndef RENDERER_H
#define RENDERER_H

#include"Vertex.h"
#include"Light.h"
#include"Texture.h"
#include"Camera.h"
#include"Shader.h"
#include"Mesh.h"
#include"Buffer.h"
#include"MyMath.h"

using namespace::std;


class Renderer
{
public:
	vector<DirectionalLight> dirLights;
	vector<PointLight> ptLights;
	Camera* camera;



	Renderer(HDC hdc,int scwidth,int scheight,Camera* cam);
	~Renderer();


	void Clear(DepthBuffer* zbuffer);

	//Rasterization
	void DrawByIndex(Mesh* m, Shader* shader, DepthBuffer* zbuffer);
	void DrawByArray(Mesh* m, Shader* shader, DepthBuffer* zbuffer);
	void DrawMesh(Mesh* m, Shader* shader, DepthBuffer* zbuffer);
	void DrawPrimitive(Vertex v0, Vertex v1, Vertex v2, Shader* shader, DepthBuffer* zbuffer);
	void RasterizeTriangle(Vertex v0, Vertex v1, Vertex v2, Shader* shader, DepthBuffer* zbuffer);

	void DrawTopTriangle(Vertex v0, Vertex v1, Vertex v2, Shader* shader, DepthBuffer* zbuffer, Vertex v3, int swapInd);
	void DrawBottomTriangle(Vertex v0, Vertex v1, Vertex v2, Shader* shader, DepthBuffer* zbuffer, Vertex v3, int swapInd);
	void DrawLine(Vertex v0, Vertex v1, Shader* shader, DepthBuffer* zbuffer, Vec4f p0, Vec4f p1, Vec4f p2);
	void DrawPixel(int x, int y,const Color& color);

	//ztest
	bool ZTestAndWrite(int x, int y,float depth, DepthBuffer* zbuffer);
	bool CVVCheck(const Vertex& vertex);
	void PreRasterization(Vertex& vertex, Buffer* buffer);


	void DrawTriangle3D(const Vec4f& v1, const Vec4f& v2, const Vec4f& v3, const Matrix& mvp);
	void DrawTriangle(int x0, int y0, int x1, int y1, int x2, int y2);
	void DrawTopTriangle(int x0, int y0, int x1, int y1, int x2, int y2);
	void DrawBottomTriangle(int x0, int y0, int x1, int y1, int x2, int y2);
	void DrawLine(int x0, int y0, int x1, int y1);
	void DrawPixel(int x, int y);
	Vec4f GetScreenCoord(const Vec4f& vec);


private:
	int deviceWidth, deviceHeight;
	HDC screenHdc;
	Texture* texture;
};









#endif // !RENDERER_H

